load(
    "//xla:xla.default.bzl",
    "xla_cc_test",
)
load("//xla/tests:build_defs.bzl", "xla_test")
load("//xla/tsl:tsl.bzl", "internal_visibility", "tsl_copts")
load("//xla/tsl:tsl.default.bzl", "filegroup", "get_compatible_with_portable")
load("//xla/tsl/mkl:build_defs.bzl", "if_graph_api", "if_onednn")
load("//xla/tsl/mkl:graph.bzl", "onednn_cc_library")
load("//xla/tsl/platform:build_config.bzl", "tf_proto_library")
load(
    "//xla/tsl/platform:build_config_root.bzl",
    "if_llvm_aarch64_available",
    "if_llvm_powerpc_available",
    "if_llvm_riscv_available",
    "if_llvm_system_z_available",
    "if_llvm_x86_available",
)
load("//xla/tsl/platform:rules_cc.bzl", "cc_library")
load("//xla/tsl/xnnpack:build_defs.bzl", "if_ynnpack")
load(":build_defs.bzl", "runtime_copts")

package(
    # copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
    default_visibility = internal_visibility([":friends"]),
    licenses = ["notice"],
)

package_group(
    name = "friends",
    includes = [
        "//xla:friends",
    ],
)

# Filegroup used to collect source files for dependency checking.
filegroup(
    name = "c_srcs",
    data = glob([
        "**/*.cc",
        "**/*.h",
    ]),
)

cc_library(
    name = "test_header_helper",
    testonly = True,
    hdrs = ["test_target_triple_helper.h"],
)

filegroup(
    name = "runtime_srcs",
    srcs = ["//xla/backends/cpu/runtime:runtime_srcs"],
    visibility = internal_visibility([":friends"]),
)

filegroup(
    name = "runtime_hdrs",
    srcs = ["//xla/backends/cpu/runtime:runtime_hdrs"],
    visibility = internal_visibility([":friends"]),
)

cc_library(
    name = "cpu_xfeed",
    srcs = ["cpu_xfeed.cc"],
    hdrs = ["cpu_xfeed.h"],
    deps = [
        ":cpu_runtime",
        "//xla:literal",
        "//xla:literal_util",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla:types",
        "//xla:util",
        "//xla/backends/cpu/runtime:xfeed_manager",
        "//xla/service:hlo_cost_analysis",
        "//xla/service:shaped_buffer",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/cleanup",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/types:span",
        "@tsl//tsl/platform:errors",
        "@tsl//tsl/platform:logging",
        "@tsl//tsl/platform:notification",
    ],
)

cc_library(
    name = "cpu_transfer_manager",
    srcs = ["cpu_transfer_manager.cc"],
    hdrs = ["cpu_transfer_manager.h"],
    deps = [
        ":cpu_runtime",
        ":cpu_xfeed",
        "//xla:literal",
        "//xla:literal_util",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla:types",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla/backends/cpu/runtime:xfeed_manager",
        "//xla/service:compiler",
        "//xla/service:generic_transfer_manager",
        "//xla/service:transfer_manager",
        "//xla/stream_executor:device_address",
        "//xla/stream_executor:platform_manager",
        "//xla/stream_executor:stream_executor_h",
        "//xla/stream_executor/host:host_platform_id",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@tsl//tsl/platform:errors",
        "@tsl//tsl/platform:logging",
    ],
    alwayslink = True,  # Contains per-platform transfer manager registration
)

cc_library(
    name = "cpu_compiler_pure",
    srcs = ["cpu_compiler.cc"],
    hdrs = ["cpu_compiler.h"],
    copts = tsl_copts(),
    deps = [
        ":conv_canonicalization",
        ":cpu_aot_compilation_result",
        ":cpu_aot_loader",
        ":cpu_executable",
        ":cpu_float_support",
        ":cpu_instruction_fusion",
        ":cpu_layout_assignment",
        ":cpu_multi_output_fusion",
        ":cpu_options",
        ":dot_op_emitter",
        ":executable_proto_cc",
        ":fusion_wrapper",
        ":ir_emission_utils",
        ":ir_emitter",
        ":ir_emitter2",
        ":metrics",
        ":parallel_task_assignment",
        ":small_while_loop_hoisting_pass",
        ":thunk_emitter",
        "//xla:debug_options_flags",
        "//xla:literal",
        "//xla:literal_pool",
        "//xla:protobuf_util",
        "//xla:shape_pool",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla:types",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla:xla_proto_cc",
        "//xla/backends/cpu:alignment",
        "//xla/backends/cpu:constant_allocation",
        "//xla/backends/cpu:target_machine_options",
        "//xla/backends/cpu:xnn_support",
        "//xla/backends/cpu/codegen:builtin_definition_generator",
        "//xla/backends/cpu/codegen:compiled_function_library",
        "//xla/backends/cpu/codegen:cpu_features",
        "//xla/backends/cpu/codegen:execution_engine",
        "//xla/backends/cpu/codegen:ir_compiler",
        "//xla/backends/cpu/codegen:jit_compiler",
        "//xla/backends/cpu/codegen:object_loader",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/backends/cpu/codegen/emitters:cpu_fusion_emitter_config",
        "//xla/backends/cpu/runtime:function_library",
        "//xla/backends/cpu/runtime:kernel_thunk",
        "//xla/backends/cpu/runtime:thunk",
        "//xla/backends/cpu/runtime:thunk_proto_cc_impl",
        "//xla/backends/cpu/runtime:thunk_proto_serdes",
        "//xla/backends/cpu/transforms:library_rewriter",
        "//xla/backends/cpu/transforms:xnn_graph_fusion",
        "//xla/backends/cpu/transforms/collectives:all_reduce_combiner",
        "//xla/hlo/analysis:alias_info",
        "//xla/hlo/analysis:hlo_ordering",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/ir:hlo_module_group",
        "//xla/hlo/pass:hlo_pass",
        "//xla/hlo/pass:hlo_pass_pipeline",
        "//xla/hlo/transforms:literal_canonicalizer",
        "//xla/hlo/transforms:operand_upcaster",
        "//xla/hlo/transforms:shape_canonicalizer",
        "//xla/hlo/transforms:while_loop_trip_count_annotator",
        "//xla/hlo/transforms/expanders:bitcast_dtypes_expander",
        "//xla/hlo/transforms/expanders:cholesky_expander",
        "//xla/hlo/transforms/expanders:comparison_expander",
        "//xla/hlo/transforms/expanders:dot_decomposer",
        "//xla/hlo/transforms/expanders:dynamic_index_splitter",
        "//xla/hlo/transforms/expanders:eigh_expander",
        "//xla/hlo/transforms/expanders:logistic_expander",
        "//xla/hlo/transforms/expanders:optimization_barrier_expander",
        "//xla/hlo/transforms/expanders:qr_expander",
        "//xla/hlo/transforms/expanders:reduce_decomposer",
        "//xla/hlo/transforms/expanders:reshape_decomposer",
        "//xla/hlo/transforms/expanders:rng_bit_generator_expander",
        "//xla/hlo/transforms/expanders:rng_expander",
        "//xla/hlo/transforms/expanders:stochastic_convert_decomposer",
        "//xla/hlo/transforms/simplifiers:algebraic_simplifier",
        "//xla/hlo/transforms/simplifiers:batch_dot_simplification",
        "//xla/hlo/transforms/simplifiers:broadcast_canonicalizer",
        "//xla/hlo/transforms/simplifiers:conditional_canonicalizer",
        "//xla/hlo/transforms/simplifiers:convolution_group_converter",
        "//xla/hlo/transforms/simplifiers:dynamic_dimension_simplifier",
        "//xla/hlo/transforms/simplifiers:flatten_call_graph",
        "//xla/hlo/transforms/simplifiers:float_normalization",
        "//xla/hlo/transforms/simplifiers:gather_simplifier",
        "//xla/hlo/transforms/simplifiers:hlo_constant_folding",
        "//xla/hlo/transforms/simplifiers:hlo_dce",
        "//xla/hlo/transforms/simplifiers:hlo_memory_scheduler",
        "//xla/hlo/transforms/simplifiers:optimize_input_output_buffer_alias",
        "//xla/hlo/transforms/simplifiers:reduce_window_resizer",
        "//xla/hlo/transforms/simplifiers:reduce_window_rewriter",
        "//xla/hlo/transforms/simplifiers:reshape_mover",
        "//xla/hlo/transforms/simplifiers:result_caster",
        "//xla/hlo/transforms/simplifiers:simplify_fp_conversions",
        "//xla/hlo/transforms/simplifiers:slice_sinker",
        "//xla/hlo/transforms/simplifiers:sort_simplifier",
        "//xla/hlo/transforms/simplifiers:sub_byte_normalization",
        "//xla/hlo/transforms/simplifiers:tree_reduction_rewriter",
        "//xla/hlo/transforms/simplifiers:tuple_simplifier",
        "//xla/hlo/transforms/simplifiers:zero_sized_hlo_elimination",
        "//xla/mlir_hlo",
        "//xla/mlir_hlo:all_passes",
        "//xla/mlir_hlo:transforms_passes",
        "//xla/service:all_reduce_promotion",
        "//xla/service:all_to_all_decomposer",
        "//xla/service:batched_gather_scatter_normalizer",
        "//xla/service:batchnorm_expander",
        "//xla/service:buffer_assignment",
        "//xla/service:call_graph",
        "//xla/service:call_inliner",
        "//xla/service:change_op_data_type",
        "//xla/service:compiler",
        "//xla/service:conditional_simplifier",
        "//xla/service:conditional_to_select",
        "//xla/service:copy_insertion",
        "//xla/service:cpu_gpu_shape_verifier",
        "//xla/service:dump",
        "//xla/service:dynamic_dimension_inference",
        "//xla/service:dynamic_padder",
        "//xla/service:executable",
        "//xla/service:float_support",
        "//xla/service:gather_expander",
        "//xla/service:hlo_cost_analysis",
        "//xla/service:hlo_cse",
        "//xla/service:hlo_execution_profile",
        "//xla/service:hlo_module_config",
        "//xla/service:hlo_profile_printer_data_cc",
        "//xla/service:hlo_proto_cc",
        "//xla/service:hlo_proto_util",
        "//xla/service:hlo_verifier",
        "//xla/service:layout_assignment",
        "//xla/service:llvm_compiler",
        "//xla/service:logical_buffer",
        "//xla/service:map_inliner",
        "//xla/service:scatter_expander",
        "//xla/service:scatter_simplifier",
        "//xla/service:select_and_scatter_expander",
        "//xla/service:sharding_propagation",
        "//xla/service:sharding_remover",
        "//xla/service:slow_operation_alarm",
        "//xla/service:topk_rewriter",
        "//xla/service:transpose_folding",
        "//xla/service:triangular_solve_expander",
        "//xla/service:while_loop_constant_sinking",
        "//xla/service:while_loop_invariant_code_motion",
        "//xla/service:while_loop_simplifier",
        "//xla/service/llvm_ir:llvm_command_line_options",
        "//xla/service/llvm_ir:llvm_util",
        "//xla/service/spmd:stateful_rng_spmd_partitioner",
        "//xla/service/spmd/shardy:constants",
        "//xla/service/spmd/shardy:shardy_xla_pass",
        "//xla/stream_executor:platform",
        "//xla/stream_executor:stream_executor_h",
        "//xla/stream_executor/host:host_platform_id",
        "//xla/tsl/concurrency:async_value",
        "//xla/tsl/platform:env",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:status",
        "//xla/tsl/platform:statusor",
        "//xla/tsl/protobuf:error_codes_proto_impl_cc",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/base:dynamic_annotations",
        "@com_google_absl//absl/cleanup",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@llvm-project//llvm:BitReader",
        "@llvm-project//llvm:BitWriter",
        "@llvm-project//llvm:Core",
        "@llvm-project//llvm:Linker",
        "@llvm-project//llvm:MC",
        "@llvm-project//llvm:Object",
        "@llvm-project//llvm:OrcJIT",
        "@llvm-project//llvm:Support",
        "@llvm-project//llvm:Target",
        "@llvm-project//llvm:TargetParser",
        "@llvm-project//llvm:TransformUtils",
        "@llvm-project//mlir:AffineDialect",
        "@llvm-project//mlir:AffineToStandard",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:ArithTransforms",
        "@llvm-project//mlir:BufferizationTransforms",
        "@llvm-project//mlir:BuiltinToLLVMIRTranslation",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:LLVMDialect",
        "@llvm-project//mlir:LLVMToLLVMIRTranslation",
        "@llvm-project//mlir:LinalgDialect",
        "@llvm-project//mlir:LinalgTransforms",
        "@llvm-project//mlir:MemRefTransforms",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:ReconcileUnrealizedCasts",
        "@llvm-project//mlir:SCFDialect",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
        "@llvm-project//mlir:ToLLVMIRTranslation",
        "@llvm-project//mlir:TransformUtils",
        "@llvm-project//mlir:Transforms",
        "@llvm-project//mlir:VectorDialect",
        "@tsl//tsl/platform:casts",
        "@tsl//tsl/platform:env",
        "@tsl//tsl/platform:errors",
        "@tsl//tsl/platform:logging",
        "@tsl//tsl/platform:platform_port",
        "@tsl//tsl/platform:status",
        "@tsl//tsl/platform:statusor",
        "@tsl//tsl/profiler/lib:traceme",
        "@tsl//tsl/profiler/lib:traceme_encode",
    ] + if_llvm_aarch64_available([
        "@llvm-project//llvm:AArch64CodeGen",  # fixdeps: keep
    ]) + if_llvm_powerpc_available([
        "@llvm-project//llvm:PowerPCCodeGen",  # fixdeps: keep
    ]) + if_llvm_riscv_available([
        "@llvm-project//llvm:RISCVCodeGen",  # fixdeps: keep
    ]) + if_llvm_system_z_available([
        "@llvm-project//llvm:SystemZCodeGen",  # fixdeps: keep
    ]) + if_llvm_x86_available([
        "@llvm-project//llvm:X86CodeGen",  # fixdeps: keep
    ]) + if_onednn([
        ":onednn_contraction_rewriter",
        ":onednn_float_support",
        ":onednn_ops_rewriter",
    ]) + if_ynnpack([
        "//xla/backends/cpu:ynn_support",
    ]),
)

cc_library(
    name = "cpu_aot_compilation_result",
    srcs = ["cpu_aot_compilation_result.cc"],
    hdrs = ["cpu_aot_compilation_result.h"],
    deps = [
        ":cpu_executable",
        ":executable_proto_cc",
        "//xla:util",
        "//xla/backends/cpu:buffer_allocation_info",
        "//xla/backends/cpu:buffer_allocation_info_util",
        "//xla/backends/cpu:constant_allocation",
        "//xla/backends/cpu:target_machine_options",
        "//xla/backends/cpu/runtime:function_library",
        "//xla/backends/cpu/runtime:thunk",
        "//xla/backends/cpu/runtime:thunk_proto_cc",
        "//xla/backends/cpu/runtime:thunk_proto_serdes",
        "//xla/hlo/analysis:alias_info",
        "//xla/hlo/ir:hlo",
        "//xla/service:buffer_assignment",
        "//xla/service:buffer_value",
        "//xla/service:compiler",
        "//xla/service:executable",
        "//xla/service:hlo_cost_analysis",
        "//xla/service:hlo_module_config",
        "//xla/service:hlo_profile_printer_data_cc",
        "//xla/service:hlo_proto_cc",
        "//xla/stream_executor:platform",
        "//xla/stream_executor/host:host_platform_id",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    # The old target name will still be used so that dependencies won't break.
    # In the future, dependencies should be cleaned up and relinked to the above
    # target if registration is not necessary.
    name = "cpu_compiler",
    srcs = ["cpu_compiler_registerer.cc"],
    hdrs = ["cpu_compiler.h"],
    deps = [
        "cpu_compiler_pure",
        ":cpu_aot_compilation_result",
        ":executable_proto_cc",
        ":thunk_emitter",
        "//xla:util",
        "//xla/backends/cpu/codegen:ir_compiler",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/hlo/ir:hlo",
        "//xla/service:buffer_assignment",
        "//xla/service:compiler",
        "//xla/service:executable",
        "//xla/service:hlo_cost_analysis",
        "//xla/service:hlo_profile_printer_data_cc",
        "//xla/service:hlo_proto_cc",
        "//xla/service:llvm_compiler",
        "//xla/stream_executor:platform",
        "//xla/stream_executor:stream_executor_h",
        "//xla/stream_executor/host:host_platform_id",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@llvm-project//llvm:Support",
        "@llvm-project//llvm:Target",
        "@llvm-project//llvm:TargetParser",
    ],
    alwayslink = True,  # Contains compiler registration
)

xla_test(
    name = "cpu_compiler_test",
    srcs = ["cpu_compiler_test.cc"],
    backends = [
        "cpu",
    ],
    tags = [
        "test_migrated_to_hlo_runner_pjrt",
    ],
    deps = [
        "//xla/hlo/testlib:verified_hlo_module",
        "//xla/tests:hlo_pjrt_test_base",
        "//xla/tests:xla_internal_test_main",
        "//xla/tsl/lib/monitoring:collected_metrics",
        "//xla/tsl/lib/monitoring:collection_registry",
        "@com_google_absl//absl/strings:string_view",
        "@tsl//tsl/platform",
        "@tsl//tsl/platform:statusor",
        "@tsl//tsl/platform:test",
    ],
)

xla_cc_test(
    name = "cpu_compiler_internals_test",
    srcs = ["cpu_compiler_internals_test.cc"],
    deps = [
        ":cpu_compiler_pure",
        "//xla/backends/cpu/codegen/emitters:cpu_fusion_emitter_config",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/hlo/testlib:verified_hlo_module",
        "//xla/service:llvm_compiler",
        "//xla/tests:hlo_test_base",
        "//xla/tests:xla_internal_test_main",
        "//xla/tsl/lib/core:status_test_util",
        "//xla/tsl/platform:statusor",
        "//xla/tsl/platform:test",
        "@com_google_absl//absl/base:nullability",
        "@com_google_absl//absl/strings:string_view",
        "@llvm-project//llvm:Core",
        "@llvm-project//llvm:Support",
    ],
)

xla_test(
    name = "cpu_aot_compiler_test",
    srcs = ["cpu_aot_compiler_test.cc"],
    backends = [
        "cpu",
    ],
    deps = [
        ":cpu_aot_compilation_result",
        ":test_header_helper",
        "//xla:debug_options_flags",
        "//xla:literal",
        "//xla:literal_util",
        "//xla/backends/cpu:target_machine_options",
        "//xla/backends/cpu/codegen:cpu_features",
        "//xla/hlo/ir:hlo",
        "//xla/service:compiler",
        "//xla/service:executable",
        "//xla/service:hlo_runner",
        "//xla/service:hlo_runner_interface",
        "//xla/stream_executor:platform",
        "//xla/stream_executor:platform_manager",
        "//xla/tests:hlo_test_base",
        "//xla/tests:literal_test_util",
        "//xla/tests:xla_internal_test_main",
        "//xla/tsl/platform:statusor",
        "//xla/tsl/platform:test",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:string_view",
        "@llvm-project//llvm:Support",
        "@llvm-project//llvm:TargetParser",
        "@tsl//tsl/platform:casts",
    ],
)

tf_proto_library(
    name = "executable_proto",
    srcs = ["executable.proto"],
    protodeps = [
        "//xla/service:hlo_proto",
        "//xla:xla_proto",
        "//xla/backends/cpu/runtime:thunk_proto",
    ],
)

cc_library(
    name = "cpu_executable",
    srcs = ["cpu_executable.cc"],
    hdrs = ["cpu_executable.h"],
    deps = [
        ":executable_proto_cc",
        "//xla:executable_run_options",
        "//xla:shape_tree",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla/backends/cpu:constant_allocation",
        "//xla/backends/cpu:target_machine_options",
        "//xla/backends/cpu/runtime:buffer_allocations",
        "//xla/backends/cpu/runtime:function_library",
        "//xla/backends/cpu/runtime:thread_pool_task_runner",
        "//xla/backends/cpu/runtime:thunk",
        "//xla/backends/cpu/runtime:thunk_executor",
        "//xla/backends/cpu/runtime:xfeed_manager",
        "//xla/hlo/ir:hlo",
        "//xla/service:buffer_assignment",
        "//xla/service:custom_call_status",
        "//xla/service:custom_call_status_internal",
        "//xla/service:executable",
        "//xla/service:hlo_execution_profile",
        "//xla/service:hlo_profile_printer_data_cc",
        "//xla/service:hlo_value",
        "//xla/service:maybe_owning_device_address",
        "//xla/service:shaped_buffer",
        "//xla/service:xla_debug_info_manager",
        "//xla/stream_executor:device_address",
        "//xla/stream_executor:device_address_allocator",
        "//xla/tsl/concurrency:async_value",
        "//xla/tsl/platform:env",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/base:dynamic_annotations",
        "@com_google_absl//absl/base:nullability",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@eigen_archive//:eigen3",
        "@tsl//tsl/platform:denormal",
        "@tsl//tsl/platform:setround",
        "@tsl//tsl/profiler/lib:traceme",
    ],
)

cc_library(
    name = "elemental_math_emitter",
    srcs = ["elemental_math_emitter.cc"],
    hdrs = ["elemental_math_emitter.h"],
    deps = [
        "//xla:xla_data_proto_cc",
        "//xla/codegen/intrinsic",
        "//xla/codegen/intrinsic:erf",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@llvm-project//llvm:Core",
        "@llvm-project//llvm:Support",
    ],
)

cc_library(
    name = "ir_emitter2",
    srcs = ["ir_emitter2.cc"],
    hdrs = ["ir_emitter2.h"],
    deps = [
        ":backend_config_proto_cc",
        ":dot_op_emitter",
        ":elemental_ir_emitter",
        ":ir_emitter",
        ":parallel_loop_emitter",
        "//xla:shape_util",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla:xla_proto_cc",
        "//xla/backends/cpu/codegen:fusion_compiler",
        "//xla/backends/cpu/codegen:kernel_api_ir_builder",
        "//xla/backends/cpu/codegen:symbol_name_util",
        "//xla/backends/cpu/codegen/emitters:cpu_fusion_emitter_config",
        "//xla/backends/cpu/codegen/emitters:cpu_fusion_emitters",
        "//xla/hlo/ir:hlo",
        "//xla/service:buffer_assignment",
        "//xla/service:hlo_module_config",
        "//xla/service/llvm_ir:dynamic_update_slice_util",
        "//xla/service/llvm_ir:fused_ir_emitter",
        "//xla/service/llvm_ir:ir_array",
        "//xla/service/llvm_ir:llvm_util",
        "//xla/service/llvm_ir:loop_emitter",
        "//xla/stream_executor:launch_dim",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_absl//absl/types:span",
        "@llvm-project//llvm:Core",
        "@llvm-project//llvm:Linker",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
    ],
)

xla_cc_test(
    name = "ir_emitter_test",
    srcs = ["ir_emitter_test.cc"],
    deps = [
        ":cpu_compiler",
        ":cpu_executable",
        ":cpu_options",
        ":ir_emitter",
        ":ir_function",
        ":target_machine_features_stub",
        "//xla:shape_util",
        "//xla/backends/cpu:alignment",
        "//xla/backends/cpu:target_machine_options",
        "//xla/backends/cpu/codegen:builtin_definition_generator",
        "//xla/backends/cpu/codegen:cpu_features",
        "//xla/backends/cpu/codegen:execution_engine",
        "//xla/backends/cpu/codegen:ir_compiler",
        "//xla/backends/cpu/codegen:jit_compiler",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/hlo/analysis:alias_info",
        "//xla/hlo/analysis:hlo_ordering",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/parser:hlo_parser",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/hlo/transforms/simplifiers:hlo_memory_scheduler",
        "//xla/service:buffer_assignment",
        "//xla/service:buffer_value",
        "//xla/service:hlo_module_config",
        "//xla/service:logical_buffer",
        "//xla/service/llvm_ir:llvm_util",
        "//xla/tsl/lib/core:status_test_util",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
        "@llvm-project//llvm:Core",
        "@llvm-project//llvm:Support",
        "@llvm-project//llvm:Target",
        "@llvm-project//mlir:IR",
        "@tsl//tsl/platform:env",
        "@tsl//tsl/platform:errors",
        "@tsl//tsl/platform:statusor",
        "@tsl//tsl/platform:test",
    ],
)

cc_library(
    name = "ir_emitter",
    srcs = ["ir_emitter.cc"],
    hdrs = ["ir_emitter.h"],
    copts = tsl_copts(),
    deps = [
        ":backend_config_proto_cc",
        ":cpu_instruction_fusion",
        ":cpu_options",
        ":cpu_runtime",
        ":dot_op_emitter",
        ":elemental_ir_emitter",
        ":ir_emission_utils",
        ":ir_function",
        ":onednn_config_proto_cc",
        ":parallel_loop_emitter",
        "//xla:literal",
        "//xla:literal_util",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla/backends/cpu/codegen:kernel_api_ir_builder",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/hlo/ir:hlo",
        "//xla/service:buffer_assignment",
        "//xla/service:collective_ops_utils",
        "//xla/service:elemental_ir_emitter",
        "//xla/service:hlo_module_config",
        "//xla/service:name_uniquer",
        "//xla/service/llvm_ir:alias_analysis",
        "//xla/service/llvm_ir:buffer_assignment_util",
        "//xla/service/llvm_ir:dynamic_update_slice_util",
        "//xla/service/llvm_ir:fused_ir_emitter",
        "//xla/service/llvm_ir:ir_array",
        "//xla/service/llvm_ir:ir_builder_mixin",
        "//xla/service/llvm_ir:llvm_loop",
        "//xla/service/llvm_ir:llvm_type_conversion_util",
        "//xla/service/llvm_ir:llvm_util",
        "//xla/service/llvm_ir:loop_emitter",
        "//xla/service/llvm_ir:tuple_ops",
        "//xla/tsl/lib/math:math_util",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:status",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/cleanup",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/meta:type_traits",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@llvm-project//llvm:Core",
        "@llvm-project//llvm:Support",
        "@llvm-project//llvm:TargetParser",
        "@llvm-project//mlir:IR",
    ] + if_onednn([":onednn_memory_util"]),
)

cc_library(
    name = "target_machine_features_stub",
    testonly = 1,
    hdrs = ["target_machine_features_stub.h"],
    deps = [
        "//xla/backends/cpu/codegen:target_machine_features",
        "@llvm-project//llvm:Core",
        "@tsl//tsl/platform:logging",
    ],
)

cc_library(
    name = "ir_function",
    srcs = ["ir_function.cc"],
    hdrs = ["ir_function.h"],
    deps = [
        ":cpu_runtime",
        ":ir_emission_utils",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla:types",
        "//xla/service:hlo_module_config",
        "//xla/service/llvm_ir:llvm_util",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
        "@llvm-project//llvm:Core",
    ],
)

cc_library(
    name = "parallel_loop_emitter",
    srcs = ["parallel_loop_emitter.cc"],
    hdrs = ["parallel_loop_emitter.h"],
    deps = [
        ":ir_emission_utils",
        "//xla/service/llvm_ir:ir_array",
        "//xla/service/llvm_ir:llvm_loop",
        "//xla/service/llvm_ir:llvm_util",
        "//xla/service/llvm_ir:loop_emitter",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/strings:string_view",
        "@llvm-project//llvm:Core",
    ],
)

cc_library(
    name = "thunk_emitter",
    srcs = ["thunk_emitter.cc"],
    hdrs = ["thunk_emitter.h"],
    copts = tsl_copts(),
    local_defines = if_graph_api(["XLA_ONEDNN_USE_GRAPH_API=1"]) + if_ynnpack(["XLA_YNNPACK"]),
    deps = [
        ":backend_config_proto_cc",
        ":cpu_options",
        ":dot_op_emitter",
        ":ir_emission_utils",
        ":ir_emitter2",
        ":parallel_fusion_emitter",
        "//xla:comparison_util",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla/backends/cpu:alignment",
        "//xla/backends/cpu:onednn_emitter",
        "//xla/backends/cpu:onednn_support",
        "//xla/backends/cpu:xnn_emitter",
        "//xla/backends/cpu:xnn_support",
        "//xla/backends/cpu/codegen:computation_kernel_emitter",
        "//xla/backends/cpu/codegen:fusion_compiler",
        "//xla/backends/cpu/codegen:fusion_emitter",
        "//xla/backends/cpu/codegen:ir_compiler",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/backends/cpu/codegen/dot:dot_kernel_emitter",
        "//xla/backends/cpu/codegen/elemental:concatenate_kernel_emitter",
        "//xla/backends/cpu/codegen/elemental:elemental_kernel_emitter",
        "//xla/backends/cpu/codegen/emitters:cpu_fusion_emitters",
        "//xla/backends/cpu/runtime:all_gather_thunk",
        "//xla/backends/cpu/runtime:all_reduce_thunk",
        "//xla/backends/cpu/runtime:all_to_all_thunk",
        "//xla/backends/cpu/runtime:call_thunk",
        "//xla/backends/cpu/runtime:collective_permute_thunk",
        "//xla/backends/cpu/runtime:collective_thunk",
        "//xla/backends/cpu/runtime:conditional_thunk",
        "//xla/backends/cpu/runtime:convolution_thunk",
        "//xla/backends/cpu/runtime:copy_thunk",
        "//xla/backends/cpu/runtime:custom_call_thunk",
        "//xla/backends/cpu/runtime:dot_thunk",
        "//xla/backends/cpu/runtime:fft_thunk",
        "//xla/backends/cpu/runtime:infeed_thunk",
        "//xla/backends/cpu/runtime:kernel_thunk",
        "//xla/backends/cpu/runtime:logical_id_thunk",
        "//xla/backends/cpu/runtime:outfeed_thunk",
        "//xla/backends/cpu/runtime:reduce_scatter_thunk",
        "//xla/backends/cpu/runtime:rng_state_thunk",
        "//xla/backends/cpu/runtime:sort_thunk",
        "//xla/backends/cpu/runtime:thunk",
        "//xla/backends/cpu/runtime:topk_thunk",
        "//xla/backends/cpu/runtime:while_thunk",
        "//xla/backends/cpu/runtime/onednn:onednn_fusion_thunk",
        "//xla/backends/cpu/runtime/xnnpack:xnn_dot_thunk",
        "//xla/backends/cpu/runtime/xnnpack:xnn_fusion_thunk",
        "//xla/codegen:kernel_definition",
        "//xla/codegen:kernel_spec",
        "//xla/codegen:llvm_kernel_source",
        "//xla/codegen:mlir_kernel_source",
        "//xla/codegen/emitters:computation_fingerprint",
        "//xla/codegen/emitters:kernel_api_builder",
        "//xla/codegen/emitters:kernel_arguments",
        "//xla/hlo/analysis:symbolic_expr",
        "//xla/hlo/ir:hlo",
        "//xla/runtime:resource_use",
        "//xla/runtime:work_group",
        "//xla/service:buffer_assignment",
        "//xla/service:collective_ops_utils",
        "//xla/service:dump",
        "//xla/service:hlo_module_config",
        "//xla/service:hlo_proto_cc",
        "//xla/service:pattern_matcher",
        "//xla/service/llvm_ir:llvm_util",
        "//xla/stream_executor:device_address",
        "//xla/tsl/platform:env",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:logging",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@llvm-project//llvm:JITLink",
        "@llvm-project//llvm:Support",
        "@llvm-project//llvm:ir_headers",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
        "@tsl//tsl/profiler/lib:traceme",
    ] + if_onednn([
        "//xla/backends/cpu/runtime/onednn:onednn_op_thunk",
    ]) + if_ynnpack([
        "//xla/backends/cpu:ynn_emitter",
        "//xla/backends/cpu:ynn_support",
        "//xla/backends/cpu/runtime/ynnpack:ynn_interop",
        "//xla/backends/cpu/runtime/ynnpack:ynn_fusion_thunk",
    ]),
)

cc_library(
    name = "tiled_dot_emitter",
    srcs = ["tiled_dot_emitter.cc"],
    hdrs = ["tiled_dot_emitter.h"],
    deps = [
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla/backends/cpu/codegen:vector_ir_builder",
        "//xla/service:hlo_module_config",
        "//xla/service/llvm_ir:kernel_support_library",
        "//xla/tsl/lib/math:math_util",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/numeric:bits",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
        "@llvm-project//llvm:Core",
    ],
)

cc_library(
    name = "dot_op_emitter",
    srcs = ["dot_op_emitter.cc"],
    hdrs = [
        "dot_op_emitter.h",
    ],
    deps = [
        ":backend_config_proto_cc",
        ":cpu_options",
        ":cpu_runtime",
        ":tiled_dot_emitter",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/hlo/ir:hlo",
        "//xla/service:hlo_module_config",
        "//xla/service/llvm_ir:ir_array",
        "//xla/service/llvm_ir:kernel_support_library",
        "//xla/service/llvm_ir:llvm_loop",
        "//xla/service/llvm_ir:llvm_util",
        "//xla/tsl/lib/math:math_util",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@llvm-project//llvm:Core",
        "@llvm-project//llvm:Support",
    ],
)

cc_library(
    name = "cpu_runtime",
    srcs = ["cpu_runtime.cc"],
    hdrs = ["cpu_runtime.h"],
    copts = runtime_copts(),
    deps = [
        ":cpu_executable_run_options",
        "//xla:executable_run_options",
        "//xla:shape_util",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla/backends/cpu/collectives:cpu_clique_key",
        "//xla/backends/cpu/collectives:cpu_cliques",
        "//xla/backends/cpu/collectives:cpu_collectives",
        "//xla/backends/cpu/collectives:in_process_collectives",
        "//xla/backends/cpu/runtime:xfeed_manager",
        "//xla/core/collectives:communicator",
        "//xla/core/collectives:rank_id",
        "//xla/hlo/parser:hlo_parser",
        "//xla/runtime:device_id",
        "//xla/service:collective_ops_utils",
        "//xla/service:computation_placer",
        "//xla/stream_executor:device_address",
        "//xla/stream_executor:stream_executor_h",
        "//xla/tsl/concurrency:async_value",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:logging",
        "//xla/tsl/platform:status",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/base:dynamic_annotations",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
        "@tsl//tsl/profiler/lib:traceme",
    ],
)

cc_library(
    name = "runtime_conv2d",
)

cc_library(
    name = "runtime_conv3d",
)

cc_library(
    name = "runtime_matmul",
)

cc_library(
    name = "runtime_single_threaded_conv2d",
)

cc_library(
    name = "runtime_single_threaded_conv3d",
)

cc_library(
    name = "runtime_single_threaded_matmul",
)

cc_library(
    name = "runtime_single_threaded_matmul_nomkl",
    compatible_with = get_compatible_with_portable(),
    copts = runtime_copts(),
    visibility = ["//visibility:public"],
    deps = [
        "//xla/tsl/framework/contraction:eigen_contraction_kernel_no_mkl",
        "@com_google_absl//absl/base:core_headers",
        "@eigen_archive//:eigen3",
    ],
)

cc_library(
    name = "runtime_key_value_sort",
    visibility = ["//visibility:public"],
)

xla_cc_test(
    name = "cpu_instruction_fusion_test",
    srcs = ["cpu_instruction_fusion_test.cc"],
    tags = ["not_run:arm"],
    deps = [
        ":cpu_instruction_fusion",
        ":cpu_options",
        "//xla:literal_util",
        "//xla:shape_util",
        "//xla:xla_data_proto_cc",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/hlo/utils:hlo_matchers",
        "//xla/service:transpose_folding",
        "//xla/tests:test_utils",
        "//xla/tests:xla_internal_test_main",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
        "@com_google_googletest//:gtest",
    ],
)

cc_library(
    name = "cpu_instruction_fusion",
    srcs = ["cpu_instruction_fusion.cc"],
    hdrs = ["cpu_instruction_fusion.h"],
    deps = [
        ":cpu_options",
        "//xla:shape_util",
        "//xla/codegen/emitters:elemental_hlo_to_mlir",
        "//xla/hlo/ir:hlo",
        "//xla/service:fusion_node_indexing_evaluation",
        "//xla/service:hlo_module_config",
        "//xla/service:instruction_fusion",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
    ],
)

cc_library(
    name = "fusion_wrapper",
    srcs = ["fusion_wrapper.cc"],
    hdrs = ["fusion_wrapper.h"],
    deps = [
        "//xla/codegen/emitters:fusion_wrapper_base",
        "//xla/hlo/ir:hlo",
        "@com_google_absl//absl/strings:string_view",
    ],
)

xla_cc_test(
    name = "fusion_wrapper_test",
    srcs = ["fusion_wrapper_test.cc"],
    deps = [
        ":fusion_wrapper",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/tests:xla_internal_test_main",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_googletest//:gtest",
    ],
)

cc_library(
    name = "ir_emission_utils",
    srcs = ["ir_emission_utils.cc"],
    hdrs = ["ir_emission_utils.h"],
    deps = [
        ":cpu_runtime",
        "//xla:shape_util",
        "//xla:window_util",
        "//xla:xla_data_proto_cc",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/hlo/ir:hlo",
        "@com_google_absl//absl/log:check",
        "@llvm-project//llvm:Core",
    ],
)

xla_cc_test(
    name = "ir_emission_utils_test",
    srcs = ["ir_emission_utils_test.cc"],
    deps = [
        ":ir_emission_utils",
        ":target_machine_features_stub",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/hlo/testlib:test",
        "//xla/tests:xla_internal_test_main",
    ],
)

cc_library(
    name = "cpu_layout_assignment",
    srcs = ["cpu_layout_assignment.cc"],
    hdrs = ["cpu_layout_assignment.h"],
    deps = [
        ":dot_op_emitter",
        ":ir_emission_utils",
        "//xla:shape_util",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/hlo/ir:hlo",
        "//xla/service:computation_layout",
        "//xla/service:layout_assignment",
        "//xla/tsl/platform:errors",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@tsl//tsl/platform:status",
    ],
)

xla_cc_test(
    name = "cpu_layout_assignment_test",
    size = "small",
    srcs = ["cpu_layout_assignment_test.cc"],
    deps = [
        ":cpu_layout_assignment",
        ":target_machine_features_stub",
        "//xla:literal",
        "//xla:shape_layout",
        "//xla:shape_util",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/hlo/testlib:test",
        "//xla/hlo/testlib:test_helpers",
        "//xla/hlo/utils:hlo_matchers",
        "//xla/service:computation_layout",
        "//xla/tests:test_utils",
        "//xla/tests:xla_internal_test_main",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@tsl//tsl/platform:status",
    ],
)

cc_library(
    name = "conv_canonicalization",
    srcs = ["conv_canonicalization.cc"],
    hdrs = ["conv_canonicalization.h"],
    deps = [
        ":cpu_runtime",
        ":ir_emission_utils",
        "//xla:permutation_util",
        "//xla:shape_util",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/pass:hlo_pass",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
        "@tsl//tsl/platform:errors",
    ],
)

xla_cc_test(
    name = "conv_canonicalization_test",
    srcs = ["conv_canonicalization_test.cc"],
    deps = [
        ":conv_canonicalization",
        ":target_machine_features_stub",
        "//xla:literal_util",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/hlo/testlib:test",
        "//xla/hlo/testlib:test_helpers",
        "//xla/tests:xla_internal_test_main",
    ],
)

cc_library(
    name = "parallel_task_assignment",
    srcs = ["parallel_task_assignment.cc"],
    hdrs = ["parallel_task_assignment.h"],
    deps = [
        ":backend_config_proto_cc",
        ":ir_emission_utils",
        "//xla:shape_util",
        "//xla:util",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/pass:hlo_pass",
        "//xla/service:hlo_cost_analysis",
        "//xla/service/llvm_ir:dynamic_update_slice_util",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@tsl//tsl/platform:platform_port",
    ],
)

xla_cc_test(
    name = "parallel_task_assignment_test",
    srcs = ["parallel_task_assignment_test.cc"],
    deps = [
        ":backend_config_proto_cc",
        ":cpu_executable",
        ":parallel_task_assignment",
        ":target_machine_features_stub",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/hlo/testlib:test",
        "//xla/service:hlo_cost_analysis",
        "//xla/tests:xla_internal_test_main",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "cpu_options",
    srcs = ["cpu_options.cc"],
    hdrs = ["cpu_options.h"],
    deps = [
        "//xla/service:hlo_module_config",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

xla_cc_test(
    name = "cpu_eigen_tensor_alignment_test",
    size = "small",
    srcs = ["cpu_eigen_tensor_alignment_test.cc"],
    deps = [
        ":ir_emission_utils",
        ":target_machine_features_stub",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/hlo/testlib:test",
        "//xla/tests:xla_internal_test_main",
    ],
)

xla_cc_test(
    name = "vectorized_reduce_with_no_vector_registers_test",
    size = "small",
    srcs = ["vectorized_reduce_with_no_vector_registers_test.cc"],
    tags = ["not_run:arm"],
    target_compatible_with = ["@platforms//cpu:x86_64"],
    deps = [
        ":cpu_compiler",
        ":cpu_transfer_manager",
        ":test_header_helper",
        "//xla:util",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/ir:hlo_module_group",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/hlo/testlib:test",
        "//xla/service:compiler",
        "//xla/tests:xla_internal_test_main",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_googletest//:gtest",
        "@llvm-project//llvm:Core",
        "@llvm-project//llvm:MC",
        "@llvm-project//llvm:Target",
        "@llvm-project//llvm:TargetParser",
        "@tsl//tsl/platform:statusor",
    ],
)

xla_cc_test(
    name = "scoped_ir_builder_test",
    srcs = ["scoped_ir_builder_test.cc"],
    deps = [
        ":cpu_executable",
        ":ir_emitter",
        ":target_machine_features_stub",
        "//xla/hlo/analysis:alias_info",
        "//xla/hlo/analysis:hlo_ordering",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/service:buffer_assignment",
        "//xla/service:buffer_value",
        "//xla/service:logical_buffer",
        "@com_google_googletest//:gtest_main",
        "@llvm-project//llvm:Core",
        "@tsl//tsl/platform:test",
    ],
)

tf_proto_library(
    name = "onednn_config_proto",
    srcs = ["onednn_config.proto"],
)

tf_proto_library(
    name = "backend_config_proto",
    srcs = ["backend_config.proto"],
    protodeps = [
        ":onednn_config_proto",
        "//xla/backends/cpu:xnn_fusion_options_proto",
        "//xla/backends/cpu:ynn_fusion_options_proto",
    ],
)

onednn_cc_library(
    name = "onednn_util",
    srcs = ["onednn_util.cc"],
    hdrs = [
        "onednn_util.h",
        "//xla/tsl/util:onednn_util_hdrs",
    ],
    copts = runtime_copts() + tsl_copts(),
    visibility = ["//visibility:public"],
    deps = [
        ":backend_config_proto_cc",
        ":onednn_config_proto_cc",
        "//xla:xla_data_proto_cc",
        "//xla/hlo/ir:hlo",
        "//xla/tsl/mkl:onednn",
        "//xla/tsl/platform:env",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/synchronization",
        "@eigen_archive//:eigen3",
        "@tsl//tsl/platform:platform_port",
    ],
)

onednn_cc_library(
    name = "onednn_memory_util",
    srcs = ["onednn_memory_util.cc"],
    hdrs = ["onednn_memory_util.h"],
    copts = runtime_copts() + tsl_copts(),
    visibility = ["//visibility:public"],
    deps = [
        "//xla:literal",
        "//xla:shape_util",
        "//xla:xla_data_proto_cc",
        "//xla/service/llvm_ir:ir_array",
        "//xla/service/llvm_ir:llvm_util",
        "//xla/tsl/mkl:onednn",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@llvm-project//llvm:Core",
    ],
)

onednn_cc_library(
    name = "onednn_matmul",
    srcs = ["onednn_matmul.cc"],
    hdrs = ["onednn_matmul.h"],
    copts = runtime_copts() + tsl_copts(),
    visibility = ["//visibility:public"],
    deps = [
        ":backend_config_proto_cc",
        ":onednn_config_proto_cc",
        ":onednn_memory_util",
        ":onednn_util",
        "//xla:executable_run_options",
        "//xla:literal",
        "//xla:shape_util",
        "//xla/hlo/ir:hlo",
        "//xla/tsl/mkl:onednn",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@eigen_archive//:eigen3",
        "@tsl//tsl/platform:platform_port",
    ],
)

onednn_cc_library(
    name = "onednn_convolution",
    srcs = ["onednn_convolution.cc"],
    hdrs = ["onednn_convolution.h"],
    copts = runtime_copts() + tsl_copts(),
    visibility = ["//visibility:public"],
    deps = [
        ":backend_config_proto_cc",
        ":onednn_config_proto_cc",
        ":onednn_memory_util",
        ":onednn_util",
        "//xla:executable_run_options",
        "//xla:shape_util",
        "//xla/hlo/ir:hlo",
        "//xla/tsl/mkl:onednn",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@eigen_archive//:eigen3",
    ],
)

onednn_cc_library(
    name = "onednn_layer_norm",
    srcs = ["onednn_layer_norm.cc"],
    hdrs = [
        "onednn_layer_norm.h",
    ],
    copts = runtime_copts() + tsl_copts(),
    visibility = ["//visibility:public"],
    deps = [
        ":backend_config_proto_cc",
        ":onednn_config_proto_cc",
        ":onednn_memory_util",
        "//xla:executable_run_options",
        "//xla/tsl/mkl:onednn",
        "//xla/tsl/platform:env",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/synchronization",
        "@eigen_archive//:eigen3",
        "@tsl//tsl/platform:platform_port",
    ],
)

onednn_cc_library(
    name = "onednn_softmax",
    srcs = ["onednn_softmax.cc"],
    hdrs = [
        "onednn_softmax.h",
    ],
    copts = runtime_copts() + tsl_copts(),
    visibility = ["//visibility:public"],
    deps = [
        ":backend_config_proto_cc",
        ":onednn_config_proto_cc",
        ":onednn_memory_util",
        "//xla:executable_run_options",
        "//xla/tsl/mkl:onednn",
        "//xla/tsl/platform:env",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/synchronization",
        "@eigen_archive//:eigen3",
        "@tsl//tsl/platform:platform_port",
    ],
)

onednn_cc_library(
    name = "onednn_pattern_utils",
    hdrs = ["onednn_pattern_utils.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":onednn_util",
        "//xla/hlo/ir:hlo",
        "//xla/service:pattern_matcher",
    ],
)

onednn_cc_library(
    name = "onednn_contraction_rewriter",
    srcs = ["onednn_contraction_rewriter.cc"],
    hdrs = [
        "onednn_contraction_rewriter.h",
        "onednn_convolution.h",
        "onednn_matmul.h",
    ],
    copts = tsl_copts(),
    deps = [
        ":backend_config_proto_cc",
        ":onednn_config_proto_cc",
        ":onednn_convolution",
        ":onednn_matmul",
        ":onednn_memory_util",
        ":onednn_pattern_utils",
        ":onednn_util",
        "//xla:executable_run_options",
        "//xla:literal",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla:types",
        "//xla:util",
        "//xla/backends/cpu/runtime/onednn:onednn_threadpool",
        "//xla/hlo/evaluator:hlo_evaluator",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/pass:hlo_pass",
        "//xla/service:hlo_cost_analysis",
        "//xla/service:pattern_matcher",
        "//xla/tsl/mkl:onednn",
        "//xla/tsl/platform:env",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_absl//absl/synchronization",
        "@eigen_archive//:eigen3",
        "@tsl//tsl/platform:logging",
        "@tsl//tsl/platform:platform_port",
    ],
)

cc_library(
    name = "onednn_ops_rewriter",
    srcs = ["onednn_ops_rewriter.cc"],
    hdrs = ["onednn_ops_rewriter.h"],
    copts = tsl_copts(),
    deps = [
        ":backend_config_proto_cc",
        ":onednn_config_proto_cc",
        ":onednn_pattern_utils",
        ":onednn_util",
        "//xla:literal_comparison",
        "//xla:literal_util",
        "//xla:shape_util",
        "//xla:util",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/pass:hlo_pass",
        "//xla/service:pattern_matcher",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
    ],
)

onednn_cc_library(
    name = "onednn_float_support",
    srcs = ["onednn_float_support.cc"],
    hdrs = ["onednn_float_support.h"],
    copts = tsl_copts(),
    deps = [
        ":onednn_contraction_rewriter",
        "//xla/hlo/ir:hlo",
        "//xla/service:float_support",
    ],
)

cc_library(
    name = "cpu_float_support",
    hdrs = ["cpu_float_support.h"],
    copts = tsl_copts(),
    deps = [
        "//xla/hlo/ir:hlo",
        "//xla/service:float_support",
    ],
)

xla_cc_test(
    name = "cpu_float_support_test",
    srcs = ["cpu_float_support_test.cc"],
    deps = [
        ":cpu_float_support",
        "//xla:shape_util",
        "//xla:xla_data_proto_cc",
        "//xla/backends/cpu/codegen:target_machine_features",
        "//xla/backends/cpu/codegen:target_machine_test_base",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/testlib:verified_hlo_module",
        "//xla/hlo/transforms/simplifiers:float_normalization",
        "//xla/service:hlo_module_config",
        "//xla/tsl/platform:statusor",
        "//xla/tsl/platform:test",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "cpu_symbol_repository",
    hdrs = ["cpu_symbol_repository.h"],
    deps = [
        "//xla:xla_proto_cc",
        "//xla/service:symbol_repository",
    ],
)

cc_library(
    name = "cpu_executable_run_options",
    hdrs = ["cpu_executable_run_options.h"],
    deps = ["//xla/backends/cpu/collectives:cpu_collectives"],
)

cc_library(
    name = "metrics",
    srcs = ["metrics.cc"],
    hdrs = ["metrics.h"],
    deps = [
        "//xla/tsl/lib/monitoring:counter",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:string_view",
        "@tsl//tsl/platform",
        "@tsl//tsl/platform:stacktrace",
        "@tsl//tsl/profiler/lib:traceme",
    ],
)

cc_library(
    name = "elemental_ir_emitter",
    srcs = ["elemental_ir_emitter.cc"],
    hdrs = ["elemental_ir_emitter.h"],
    deps = [
        ":elemental_math_emitter",
        "//xla:util",
        "//xla/codegen/intrinsic",
        "//xla/codegen/intrinsic:exp",
        "//xla/codegen/intrinsic:rsqrt",
        "//xla/codegen/intrinsic:tanh",
        "//xla/hlo/ir:hlo",
        "//xla/service:elemental_ir_emitter",
        "//xla/service/llvm_ir:llvm_util",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_absl//absl/types:span",
        "@llvm-project//llvm:ir_headers",
    ],
)

cc_library(
    name = "small_while_loop_hoisting_pass",
    srcs = ["small_while_loop_hoisting_pass.cc"],
    hdrs = ["small_while_loop_hoisting_pass.h"],
    deps = [
        ":cpu_executable",
        "//xla:util",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/pass:hlo_pass",
        "//xla/service:collective_ops_utils",
        "//xla/service:hlo_cost_analysis",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:string_view",
    ],
)

cc_library(
    name = "parallel_fusion_emitter",
    srcs = ["parallel_fusion_emitter.cc"],
    hdrs = ["parallel_fusion_emitter.h"],
    deps = [
        "//xla/backends/cpu/codegen:fusion_compiler",
        "//xla/backends/cpu/codegen:fusion_emitter",
        "//xla/codegen:kernel_definition",
        "//xla/codegen:kernel_spec",
        "//xla/codegen:llvm_kernel_source",
        "//xla/codegen:mlir_kernel_source",
        "//xla/hlo/ir:hlo",
        "//xla/service:buffer_assignment",
        "//xla/tsl/platform:env",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/functional:bind_front",
        "@com_google_absl//absl/functional:function_ref",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/synchronization",
        "@llvm-project//mlir:IR",
    ],
)

xla_test(
    name = "parallel_fusion_emitter_test",
    srcs = ["parallel_fusion_emitter_test.cc"],
    backends = [
        "cpu",
    ],
    deps = [
        ":parallel_fusion_emitter",
        "//xla/backends/cpu/codegen:fusion_compiler",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/testlib:filecheck",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/service/llvm_ir:llvm_util",
        "//xla/tsl/platform:env",
        "//xla/tsl/platform:statusor",
        "//xla/tsl/platform:threadpool_interface",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_googletest//:gtest_main",
        "@llvm-project//llvm:JITLink",
        "@llvm-project//llvm:ir_headers",
        "@llvm-project//mlir:IR",
    ],
)

cc_library(
    name = "cpu_multi_output_fusion",
    srcs = ["cpu_multi_output_fusion.cc"],
    hdrs = ["cpu_multi_output_fusion.h"],
    deps = [
        "//xla:shape_util",
        "//xla/codegen/emitters:elemental_hlo_to_mlir",
        "//xla/hlo/analysis:alias_info",
        "//xla/hlo/ir:hlo",
        "//xla/service:multi_output_fusion",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/strings:string_view",
    ],
)

xla_cc_test(
    name = "cpu_multi_output_fusion_test",
    srcs = ["cpu_multi_output_fusion_test.cc"],
    deps = [
        ":cpu_multi_output_fusion",
        "//xla/hlo/analysis:alias_info",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/hlo/utils:hlo_matchers",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_googletest//:gtest_main",
    ],
)

xla_cc_test(
    name = "small_while_loop_hoisting_pass_test",
    srcs = ["small_while_loop_hoisting_pass_test.cc"],
    deps = [
        ":backend_config_proto_cc",
        ":small_while_loop_hoisting_pass",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/testlib:hlo_hardware_independent_test_base",
        "//xla/hlo/testlib:test",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_googletest//:gtest_main",
    ],
)

xla_cc_test(
    name = "metrics_test",
    srcs = ["metrics_test.cc"],
    tags = [
        # Streamz recording doesn't work in OSS.
        "no_oss",
    ],
    deps = [
        ":metrics",
        "//xla/tests:xla_internal_test_main",
        "//xla/tsl/lib/monitoring:collected_metrics",
        "//xla/tsl/lib/monitoring:collection_registry",
        "@tsl//tsl/platform:test",
    ],
)

cc_library(
    name = "cpu_aot_loader",
    srcs = ["cpu_aot_loader.cc"],
    hdrs = ["cpu_aot_loader.h"],
    deps = [
        ":cpu_aot_compilation_result",
        ":executable_proto_cc",
        "//xla:util",
        "//xla/backends/cpu:target_machine_options",
        "//xla/backends/cpu/codegen:builtin_definition_generator",
        "//xla/backends/cpu/codegen:cpu_features",
        "//xla/backends/cpu/codegen:execution_engine",
        "//xla/backends/cpu/codegen:ir_compiler",
        "//xla/backends/cpu/codegen:object_loader",
        "//xla/backends/cpu/runtime:function_library",
        "//xla/hlo/ir:hlo",
        "//xla/service:compiler",
        "//xla/service:executable",
        "//xla/service:hlo_module_config",
        "//xla/service/llvm_ir:llvm_command_line_options",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@llvm-project//llvm:Support",
        "@llvm-project//llvm:Target",
        "@llvm-project//llvm:TargetParser",
        "@llvm-project//llvm:ir_headers",
    ] + if_llvm_aarch64_available([
        "@llvm-project//llvm:AArch64CodeGen",  # fixdeps: keep
    ]) + if_llvm_powerpc_available([
        "@llvm-project//llvm:PowerPCCodeGen",  # fixdeps: keep
    ]) + if_llvm_riscv_available([
        "@llvm-project//llvm:RISCVCodeGen",  # fixdeps: keep
    ]) + if_llvm_system_z_available([
        "@llvm-project//llvm:SystemZCodeGen",  # fixdeps: keep
    ]) + if_llvm_x86_available([
        "@llvm-project//llvm:X86CodeGen",  # fixdeps: keep
    ]),
)
